#ifndef __HTTPRESPONSE_H__
#define __HTTPRESPONSE_H__

#include <unordered_map>
#include <string>

class MsgBuffer;

enum class HttpStatusCode : int
{
    kUnknown,
    kOK = 200,
    kMovedPermanently = 301,
    kBadRequest = 400,
    kNotFound = 404
};

class HttpResponse
{
    using self = HttpResponse;
public:
    explicit HttpResponse()
    {
    }
    HttpResponse(const HttpResponse& other) = default;
    HttpResponse& operator=(const HttpResponse& other) = default;

    self& setStatusCode(HttpStatusCode code)
    {
        status_ = code;
        return *this;
    }
    self& setMessage(std::string msg)
    {
        message_ = std::move(msg);
        return *this;
    }
    self& setClose(bool close)
    {
        close_ = close;
        return *this;
    }
    self& addHeader(std::string key, std::string value)
    {
        headers_[std::move(key)] = std::move(value);
        return *this;
    }
    self& setBody(std::string body)
    {
        body_ = std::move(body);
        return *this;
    }
    const self& appendToBuffer(MsgBuffer* output) const;

    operator bool() const
    {
        return close_;
    }

private:
    using HeaderMap = std::unordered_map<std::string, std::string>;
    bool close_{true};
    HeaderMap headers_;
    HttpStatusCode status_{HttpStatusCode::kUnknown};
    std::string message_;
    std::string body_;
};

#endif // __HTTPRESPONSE_H__